package com.bx.implatform.controller;

import com.bx.implatform.dto.BoxMessageDTO;
import com.bx.implatform.dto.SearchBoxMessageDTO;
import com.bx.implatform.entity.UserBoxMessage;
import com.bx.implatform.result.Result;
import com.bx.implatform.result.ResultUtils;
import com.bx.implatform.service.UserBoxMessageService;
import com.bx.implatform.vo.UserBoxMessageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Tag(name = "盲盒消息接口")
@RestController
@RequestMapping("/box/message")
@RequiredArgsConstructor
public class BoxMessageController {

    private final UserBoxMessageService boxMessageService;

    @PostMapping("/send")
    @Operation(summary = "发盲盒", description = "发盲盒")
    public Result<Boolean> sendMessage(@Valid @RequestBody BoxMessageDTO vo) {
        return ResultUtils.success(boxMessageService.send(vo));
    }

    @PostMapping("/receive")
    @Operation(summary = "收盲盒", description = "收盲盒")
    public Result<UserBoxMessageVO> selectBoxMessage(@RequestBody SearchBoxMessageDTO messageDTO) {
        return ResultUtils.success(boxMessageService.receive(messageDTO));
    }

    @GetMapping("/history")
    @Operation(summary = "查询盲盒历史记录", description = "查询盲盒历史记录")
    public Result<List<UserBoxMessage>> history(
            @NotNull(message = "页码不能为空") @RequestParam Long page,
            @NotNull(message = "size不能为空") @RequestParam Long size) {
        return ResultUtils.success(boxMessageService.findHistoryBoxMessage(page, size));
    }



}

